<?php

namespace app\common\model;

use think\facade\Db;
use think\Model;

class Student extends Model
{
    //自动生成写入时间
    protected $autoWriteTimestamp = true;

    public function student($data)
    {
        if (empty($data['classes_id'])) {
            return Db::table('student')
                ->alias('s')
                ->join('classes c', 's.classes_id = c.id')
                ->field('s.*,c.name as classes_name')
                ->paginate($data);
        } else {
            return Db::table('student')
                ->alias('s')
                ->join('classes c', 's.classes_id = c.id')
                ->field('s.*,c.name as classes_name')
                ->where(['s.classes_id' => $data['classes_id']])
                ->paginate($data);
        }
    }
    /**
     * 获取某个管理员信息
     * @param $username
     * @return User|array|mixed|Model|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getStudent($data)
    {
        return $this->where($data)->withoutField('password')->find();
    }
}